import { Action, ActionKey, locale, loading, modelService, GraphNode, CheckElementsByRulesDto, ModelValidateDegree, rmi } from "@/mdesign-lib/mdesign-app.umd.js";

export class ValidateModelAllAction extends Action {
  keyName = ActionKey.ValidateModelAll;
  desc = "递归校验模型";
  onTreeMenuClick(graphNode) {
    if (!graphNode) return;
    this.run(graphNode);
  }
  async run(graphNode) {
    if (!app.activeProject) return;
    loading.popup(locale.t("校验中") + "...");
    const ruleInstanceIds = await modelService.queryValidationRuleInstanceIds({
      projectId: app.activeProjectId,
      severity: ModelValidateDegree.ERROR
    });
    const params = {
      projectId: app.activeProjectId,
      ruleInstanceIds,
      excludeReadOnly: false,
      instanceIds: [graphNode.id],
      isCheckChildren: true,
      severity: ModelValidateDegree.ERROR
    } as CheckElementsByRulesDto;
    await rmi.invokeAction(ActionKey.checkElementsByRules, [JSON.parse(JSON.stringify(params))]);
    loading.close();
  }
}
